

$(function () {
    $.getJSON(
        "/memorypalace/deckaction_mydeck.action",
        function(bean){
            console.log(bean);
            $("#products").html("");
            $.each(bean.data,function (i, deck) {
                var h = '<div class="item  col-xs-4 col-lg-4">'+
                            '<input class="deckId" type="hidden" id="deckId'+i+'"'+
                                'value="'+deck.deckId+'">'+
                            '<div class="thumbnail" style="position: relative;">'+
                                '<a href="/memorypalace/card.html?deckId='+deck.deckId+'">'+
                                    '<div class="caption" onClick="getCards()" style="margin-top: 60px;margin-bottom: 60px;">'+
                                        '<h3 id="_name'+i+'"'+
                                            'class="group inner list-group-item-heading"'+
                                            'style="text-align: center;font-weight: bold;">'+deck.deckName+'</h3>'+
                                    '</div>'+
                                '</a>'+
                                '<div style="position: absolute;right: 4px;bottom: 4px;">'+

                                    '<a class="btn btn-default theme-login" id="xiugai'+i+'"'+
                                        'onclick="modify(this.id)">修改</a>'+
                                    '<a href="javascript:shanchu()" class="btn btn-danger">删除</a>'+

                                '</div>'+
                            '</div>'+
                        '</div>';

                $("#products").append(h);
                $("#products").trigger('create');
                $('.theme-login').click(function () {
                    $('.theme-popover-mask').fadeIn(100);
                    $('.theme-popover').slideDown(200);
                });
            });

        }
    );
});

//获得deckId
var getCards = function () {
    var deckId = $("#deckId").attr("value");
    $.getJSON("/memorypalace/deckaction_getcards.action?deckId=" + deckId,
        function (json) {
            alert(json);
        });
};
//实现网格模式、列表模式的切换
$(document).ready(function () {
    $('#list').click(function (event) {
        event.preventDefault();
        $('#products .item').addClass('list-group-item');
    });
    $('#grid').click(function (event) {
        event.preventDefault();
        $('#products .item').removeClass('list-group-item');
        $('#products .item').addClass('grid-group-item');
    });
});
/* window.onload = function() {
 var addFlag = document.getElementById('addFlag');
 if (addFlag.value == 'true') {
 alert('添加成功');

 window.opener.location.reload();//刷新父界面   加载新添加的员工信息
 } else if (addFlag.value == 'false') {
 alert('添加失败');
 }

 }; */
/* window.onload = function() {
 var deleteFlag = document.getElementById('deleteFlag');
 if (deleteFlag.value == 'true') {
 alert('删除成功');

 window.opener.location.reload();//刷新父界面   加载新添加的员工信息
 } else if (deleteFlag.value == 'false') {+++++++++++++++++++
 alert('删除失败');
 }
 };

 window.onload = function(){
 var modifyFlag = document.getElementById('modifyFlag');
 if(modifyFlag.value=='true'){
 alert('修改成功');

 window.opener.location.reload();//刷新父界面   加载新添加的员工信息
 }else if(modifyFlag.value=='false'){
 alert('修改失败');
 }
 }; */
//ajax添加数据
var afterAddDeck = function () {
    var deckName = $("#deckName").val();
    $.getJSON(
        "/memorypalace/deckaction_adddeck.action?deckName=" + deckName,
        function (json) {
            //alert(json);
            if (json) {
                alert("添加成功");
            } else {
                alert("添加失败");
            }
        }
    );

};

//ajax删除数据
var shanchu = function () {

    var deckId = $(".deckId").val();
    if (confirm('是否真的要删除?')) {
        $.getJSON(
            "/memorypalace/deckaction_deletedeck.action?deckId=" + deckId,
            function (json) {

                if (json) {
                    alert('删除成功');
                    location.reload();
                } else {
                    alert('删除失败');
                }
            });
    }

};

//ajax修改数据
var afterModifyDeck = function () {
    var deckName = $("#inputdeckName").val();
    var deckId = $("#inputdeckName").attr("deckId");
    $.getJSON(
        "/memorypalace/deckaction_modifydeck.action?deckName=" + deckName +
        "&deckId=" + deckId,
        function (json) {
            //alert(json);
            if (json) {
                alert("修改成功");
            } else {
                alert("修改失败");
            }
        }
    );

};

//添加弹窗

var w, h, className;
function getSrceenWH() {
    w = $(window).width();
    h = $(window).height();
    $('#dialogBg').width(w).height(h);
}

window.onresize = function () {
    getSrceenWH();
};
$(window).resize();

$(function () {
    getSrceenWH();

    //显示弹框
    $('.box a').click(function () {
        className = $(this).attr('class');
        $('#dialogBg').fadeIn(300);
        $('#dialog').removeAttr('class').addClass('animated ' + className + '').fadeIn();
    });

    //关闭弹窗
    $('.claseDialogBtn').click(function () {
        $('#dialogBg').fadeOut(300, function () {
            $('#dialog').addClass('bounceOutUp').fadeOut();
        });
    });
});

//修改牌组弹窗
$(function () {

    $('.theme-login').click(function () {
        $('.theme-popover-mask').fadeIn(100);
        $('.theme-popover').slideDown(200);
    });
    $('.theme-poptit .close').click(function () {
        $('.theme-popover-mask').fadeOut(100);
        $('.theme-popover').slideUp(200);
    });


});
var modify = function (id) {
    // 1.获取点击的牌组的名称
    var deckNameId = id.replace("xiugai", "_name");
    var deckIdId = id.replace("xiugai", "deckId");
    var deckId = $("#" + deckIdId).val();
    var title = $("#" + deckNameId);
    var deckName = $("#" + deckNameId).html();
    // 2.传过去
    console.log($(".theme-popover .theme-poptit input[type!=submit]"));
    $("#inputdeckName").val(deckName);
    $("#inputdeckName").attr({"deckId": deckId});
};